
import { ExceptionFilter, Catch, ArgumentsHost,HttpException } from '@nestjs/common'
 
import {Request,Response} from 'express';


@Catch(HttpException)
export class HttpFilter implements ExceptionFilter {
    catch(exception: HttpException, host: ArgumentsHost) {
        const ctx = host.switchToHttp();
        let request =  ctx.getRequest<Request>();
        let response =  ctx.getResponse<Response>();
        let status = exception.getStatus();
        response.status(status).json({
            data: exception.message,
            time: new Date().getTime(),
            success: false,
            path:request.url,
            status
        })
    }
    
}
